package com.egao.common.publicly;

import cn.hutool.core.io.FileUtil;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.utils.FileServerUtil;
import com.egao.common.core.web.JsonResult;
import com.egao.common.publicly.service.PubliclyResumeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.mail.MessagingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URISyntaxException;

/**
 * 推送简历
 * @author pyx
 */
@Api(tags = "推送简历")
@RestController
@RequestMapping("${api}")
public class PubliclyResumeController {
    @Autowired
    private PubliclyResumeService publiclyResumeService;

    @Value("${minio.resumeDir}")
    private String resumeDir;

    @Value("${config.upload-location:0}")
    private Integer uploadLocation;

    @ApiOperation("推送简历")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "推送信息id", required = true, dataType = "int", paramType = "query"),
    })
    @GetMapping("/publicly/push/resume")
    public JsonResult recruitResume(Integer id) throws MessagingException {
        return publiclyResumeService.pushResume(id);
    }


    @ApiOperation(value = "简历下载")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "studentId", value = "studentId", required = true, dataType = "String")
    })
    @GetMapping("/temp/publicly/inten/upload")
    public void doget(HttpServletRequest request, HttpServletResponse response,Integer studentId) {
//        String url = resumeDir + "\\resume\\" + studentId+ "\\resume.pdf";
//        File file = FileUtil.file(url);
//        String s = File.listRoots()[uploadLocation] + "/upload/pdf/";
//        FileServerUtil.preview(file, true, null, s, response, request);
    }

}
